export default class BaseObject {
	constructor() {
	}
	
	objectSetValue(source){
		for (let var1 in this) {
			if(source&&source[var1]){
				if(this.setImageKeys().includes(var1)){
					this[var1]=this.checkURL(source?.[var1] || '', getApp().globalData.img_pre)
				}else{
					this[var1]=source?.[var1]||''
				}
				delete source[var1];
			}
		}
		
		if(source){
			for (let key in source) {
				this[key]=source?.[key]||''
			}
		}
	}
	
	setImageKeys(){
		return[]
	}
	
	checkURL(URL, address) {
		var str = URL;
		//判断URL地址的正则表达式为:http(s)?://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?
		//下面的代码中应用了转义字符"\"输出一个字符"/"
		var Base64 = /^\s*data:([a-z]+\/[a-z0-9-+.]+(;[a-z-]+=[a-z0-9-]+)?)?(;base64)?,([a-z0-9!$&',()*+;=\-._~:@\/?%\s]*?)\s*$/i;
		var Expression = /http(s)?:\/\/([\w-]+\.)+[\w-]+(\/[\w- .\/?%&=]*)?/;
		
		var objB64Exp = new RegExp(Base64);
		if(objB64Exp.test(str)==true){
			return URL || '';
		}
		var objExp = new RegExp(Expression);
		if (objExp.test(str) == true) {
			return URL || '';
		} else {
			return URL ? address + URL : ''
		}
	}
}